package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.dao.ImplementationArtifactRequestDao;
import com.rmt.www.vo.ImplementationArtifactRequest;
import com.rmt.www.vo.Request;

public class ImplementationArtifactRequestDaoImpl implements
		ImplementationArtifactRequestDao {
	
	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public void deleteImplementationArtifactRequestById(int id) {
		this.jdbcTemplate.update("update implartifactrequest set status='deleted' where id=?", new Object[]{id}, new int[]{java.sql.Types.INTEGER});

	}

	public ImplementationArtifactRequest getImplementationArtifactRequestById(int id) {
		return (ImplementationArtifactRequest) this.jdbcTemplate.queryForObject("select* from implartifactrequest where id=? and status != 'deleted'", 
				new Object[]{id}, new ImplementationArtifactRequestRowMapper());
	}
	
	

	@SuppressWarnings("unchecked")
	public List<ImplementationArtifactRequest> getImplementationArtifactRequestsByPId(
			int pid) {
		return this.jdbcTemplate.query("select * from implartifactrequest where pid=? and status != 'deleted'", 
				new Object[]{pid}, new int[]{java.sql.Types.INTEGER}, new ImplementationArtifactRequestRowMapper());
	}

	public void insertImplArtifactRequest(ImplementationArtifactRequest request) {
		jdbcTemplate.update("insert into implartifactrequest(pid,title,function,input,output,processingsteps,algorithm,errorhandling,code,priority,effort,cost,risk,comment,createrid,createdtime,updaterid,updatedtime,updatedtimes,version,status,language,implartifactid,requesttype) " +
				"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
				new Object[]{
					request.getPid(),
					request.getTitle(),
					request.getFunction(),
					request.getInput(),
					request.getOutput(),
					request.getProcessingsteps(),
					request.getAlgorithm(),
					request.getErrorhandling(),
					request.getCode(),
					request.getPriority(),
					request.getEffort(),
					request.getCost(),
					request.getRisk(),
					request.getComment(),
					request.getCreaterid(),
					request.getCreatedtime(),
					request.getUpdaterid(),
					request.getUpdatedtime(),
					request.getUpdatedtimes(),
					request.getVersion(),
					request.getStatus(),
					request.getLanguage(),
					request.getImplartifactid(),
					request.getRequesttype()
				},new int[] {
					java.sql.Types.INTEGER,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.INTEGER,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.INTEGER,
					java.sql.Types.TIMESTAMP,
					java.sql.Types.INTEGER,
					java.sql.Types.TIMESTAMP,
					java.sql.Types.INTEGER,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.VARCHAR,
					java.sql.Types.INTEGER,
					java.sql.Types.VARCHAR
				});
	}

}
